package com.example.core.convert.model;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Field;

public class ModelConvertor_ModelToString implements ModelConvertor {

    Logger logger = LoggerFactory.getLogger(getClass());
    private String tPropertyName;

    public ModelConvertor_ModelToString(String tPropertyName) {
        this.tPropertyName = tPropertyName;
    }

    @Override
    public void convertor(Object form, Object val) throws Exception {
        if (val != null){
            Field field = ReflectionUtils.findField(form.getClass(), tPropertyName);
            field.setAccessible(true);
            field.set(form, val);
        }
    }
}
